#
# 添加默认构造函数
# @author lukecheng
#

#-*-encoding:utf-8-*-
import os

sep = os.sep

root = os.getcwd()

def add_constructor(path, filename):
	has_constructor = False
	constructor_name = filename[:-5] + "()"

	fp = open(path, "r", encoding= 'utf-8')
	code = fp.read()
	if code.find(constructor_name) < 0:
		has_constructor = False
	else:
		has_constructor = True
	fp.close()

	if not has_constructor:
		eof = code.rfind("}")
		new_code = '%s\n\tpublic %s {}\n}' % (code[:eof], constructor_name)
		fp = open(path, "w", encoding= 'utf-8')
		fp.write(new_code)
		fp.close()

for dp, subpaths, files in os.walk(root, False):
	for fp in files:
		if '.java' == fp[-5:]:
			realpath = "%s%s%s" % (dp, sep, fp)
			add_constructor(realpath, fp)


